<div class="CartWrap" id="cart-index">
    <{if $is_empty}>
    <{include file="site/cart/cart_empty.html" app=b2c}>
    <{else}>

<div class="cart-nav stepbj1"><span class="step1"><{t}>购物车<{/t}></span><span class="step2"><{t}>填写订单并确认<{/t}></span><span class="step3"><{t}>成功提交订单<{/t}></span><span class="my-cart"><{t}>我的购物车<{/t}></span></div>

<form id="form-cart" action="<{if !$checkout_link}><{link app="b2c" ctl="site_cart" act="checkout"}><{else}><{$checkout_link}><{/if}>" method="post" extra="cart">
  <{include file="site/cart/cart_main.html" app=b2c}>
</form>
<{/if}>
</div>
<script>
/*
*CartJs update :2009-9-8 11:33:20
*
*@author litie[aita]shopex.cn
*
*------------------------/


/*购物车小图mouseenter效果*/
function thumb_pic(){
  if(!$('goodsbody'))return;
  var cart_product_img_viewer=new Element('div',{styles:{'position':'absolute','zIndex':500,'opacity':0,'border':'1px #666 solid'}}).inject(document.body);
  var cpiv_show=function(img,event){

      if(!img)return;
      cart_product_img_viewer.empty().adopt($(img).clone().removeProperties('width','height').setStyle('border','1px #fff solid')).fade(1);

      var size = window.getSize(), scroll = window.getScroll();
        var tip = {x: cart_product_img_viewer.offsetWidth, y: cart_product_img_viewer.offsetHeight};
        var props = {x: 'left', y: 'top'};
        for (var z in props){
            var pos = event.page[z] + 10;
            if ((pos + tip[z] - scroll[z]) > size[z]) pos = event.page[z] - 10 - tip[z];
            cart_product_img_viewer.setStyle(props[z], pos);
        }

  };

   $$('#cart-index .cart-product-img').each(function(i){
       new Asset.image(i.get('isrc'),{onload:function(img){
   if(!img)return;
           var _img=img.zoomImg(50,50);
     if(!_img)return;
           _img.setStyle('cursor','pointer').addEvents({
              'mouseenter':function(e){
                 cpiv_show(_img,e);
              },
              'mouseleave':function(e){
                cart_product_img_viewer.fade(0);
              }
           });
           i.empty().adopt(new Element('a',{href:i.get('ghref'),target:'_blank',styles:{border:0}}).adopt(_img));
       },onerror:function(){
            i.empty();

       }});

   });


};



thumb_pic();


/*购物车处理*/
void function(){
    var cartForm = $('form-cart');
    var cartTotalPanel = $('cartitems');
    Cart=new Object();
    Cart.utility={
        keyCodeFix:[48,49,50,51,52,53,54,55,56,57,96,97,98,99,100,101,102,103,104,105,8,9,46,37,39],
        accAdd:function(arg1,arg2){
            var r1,r2,m;
            try{r1=arg1.toString().split(".")[1].length;}catch(e){r1=0;}
            try{r2=arg2.toString().split(".")[1].length;}catch(e){r2=0;}
            m=Math.pow(10,Math.max(r1,r2));
            return (arg1*m+arg2*m)/m;
        }
    };


    Object.append(Cart,{
         removeItem:function(handle){
             Ex_Dialog.confirm('<{t}>确认删除？<{/t}>', function(e){
                 if(!e) return;
                 var item = $(handle).getParent('tr');
                 var remoteURL = item.get('urlremove');

                 item.getElements('input').set('disabled',true);
                 if(item.hasClass('havechild')){
                     var chlid_id= item.get('chlid_id');
                     if($(item).getParent('table') && $(item).getParent('table').getElements('.'+chlid_id))
                     $(item).getParent('table').getElements('.'+chlid_id).each(function(ell){ell.getElements('input').set('disabled',true);});
                 }

                 this.updateTotal(remoteURL,{
                     onRequest:function(){
                        if(!Browser.ie6){
                             item.getFirst().set('html','<{t}>正在删除...<{/t}>');
                             item.setStyles({'background':'#FBE3E4','opacity':1})
                        }
                     },
                     onComplete:function(){
                         //删除配件
                         if(item.hasClass('havechild')){
                           var chlid_id= item.get('chlid_id');
                           if($(item).getParent('table') && $(item).getParent('table').getElements('.'+chlid_id))
                           $(item).getParent('table').getElements('.'+chlid_id).each(function(ell){ell.destroy();});
                         }

                         item.destroy();

                         var rule_id=$$('.order_rule_id'),
                             order_id=$$('tr[order_rule_id]');
                         if(!!order_id.length){
                            order_id.each(function(tr){
                                if(!rule_id.length)return tr.destroy();
                                var _tr_destory = rule_id.some(function(el,i){
                                    if(tr.get('order_rule_id').split(',').contains(el.value)) return true;
                                });
                                if (!_tr_destory) tr.destroy();
                            });
                         }
                         if($$('.cart-number')) $$('.cart-number').set('text',Cookie.read('S[CART_NUMBER]')||0);
                         if($$('.cart-count')) $$('.cart-count').set('text',Cookie.read('S[CART_COUNT]')||0);
                         if ($$('.cart-money-total')[0]) $$('.cart-money-total')[0].set('text',Cookie.read('S[CART_TOTAL_PRICE]')||0);

                         if ($('goodsbody').getElement('tbody').get('html').trim() == ''){
                             $('goodsbody').destroy();
                         }
                     }
                 });
             }.bind(this));
         },
         ItemNumUpdate:function(numInput,num,evt){
              var _float_store = numInput.getParent('tr').getAttribute('floatstore').toInt() || 0;
              var type=['toInt','toFloat'];

              var forUpNum=numInput.value[type[_float_store]]();

              if(evt&&new Event(evt).target!=numInput){
                 forUpNum = Cart.utility.accAdd((isNaN(forUpNum)?1:forUpNum), num);
              }

             if(forUpNum[type[_float_store]]()<=0)forUpNum=1;

              numInput.value = forUpNum.limit(0,Number.MAX_VALUE);


              var _goods_number = numInput.getParent('tr').getAttribute('number')[type[_float_store]]();


              this.updateItem(numInput,numInput.getParent('tr'));
              this.__forUpNum = forUpNum;
              this.__goods_number = _goods_number;
              if(forUpNum > _goods_number) {
                //numInput.value = _goods_number;
                MessageBox.error('<{t}>数量错误！<{/t}><br/>' + numInput.getParent('tr').getAttribute('g_name') + "<{t}>(可购买数量为：<{/t}>" + _goods_number + ") " );
                return false;
              }
         },
         updateItem:function(input,item){

             if(input.value=='NaN') { input.value=1;return false;}
             item.retrieve('request',{cancel:function(){}}).cancel();

             item.store('request',new Request({
                url:item.get('urlupdate'),
                data:input.getParent('tr'),
                method:'post',
                onSuccess:function(res){
                     $('cart-ajax-update').set('html', res);
                     this.updateNum(input);
                     if ($$('.cart-money-total')[0]) $$('.cart-money-total')[0].set('text',Cookie.read('S[CART_TOTAL_PRICE]')||0);
                 }.bind(this),
                onFailure:function(xhr){
                     input.focus();
                     input.value = item.get('buy_store');
                     if( this.__goods_number>this.__forUpNum ) MessageBox.error("<{t}>数量错误！或 累计购买数量超出每人限购数量<{/t}>");
                 }.bind(this)
             }).send());
         },
         updateNum:function(input){
                 var item=input.getParent('tr'),json;
                 if( !$('update-ajax-num') ) {
                   // item.remove();
                   return false;
                 }else{
                    json=JSON.decode($('update-ajax-num').value);
                 }
                 item.getElements('h6.font-red').set('html',$('update-ajax-num').get('error_msg'));

                 item.set('buy_store',input.value);
                 ['buy_price','consume_score'].each(function(str,i){
                         if(json){
                              var el=item.getElement('.'+str);
                              el.set('text',json[str]);
                         }
                 });
         },
         updateTotal:function(remoteURL,options){
            options = options||{};
            new Request.HTML(Object.append({update:$('cart-ajax-update'),'method':'post',url:remoteURL,data:$('form-cart')},options)).send();
            if ($$('.cart-money-total')[0]) $$('.cart-money-total')[0].set('text',Cookie.read('S[CART_TOTAL_PRICE]')||0);
         },
         empty:function(remoteURL){
            Ex_Dialog.confirm('<{t}>确认清空购物车？<{/t}>', function(e){
                if(!e) return;
                new Request({
                    url:remoteURL,
                    onComplete:function(){
                        MessageBox.success('<{t}>清空购物车成功,正在准备刷新本页<{/t}>',{
                            onFlee:function(e){
                                location.reload();
                            }
                        });
                    }
                }).post();
            });
         }
    });

if($('cart-items'))
    $('form-cart').getLast('div').addEvents({
        'mousedown':function(e){
            var target=$(e.target);
            if(target.hasClass('numadjust'))
            target.addClass('active');
        },
        'mouseup':function(e){
            var target=$(e.target);
            if(target.hasClass('numadjust'))
            target.removeClass('active')
        },
        'keydown':function(e){
            var target=$(e.target);
            if(target.hasClass('textcenter')){
                if(target.getParent('tr').getAttribute('floatstore').toInt()==1) {
                    if(e.code==110 || e.code==190) e.code=48; //小数
                }
                if(!Cart.utility.keyCodeFix.contains(e.code)){e.stop();}
            }
         },
       /* 'change':function(e){
            var target=$(e.target);
            if(target.hasClass('textcenter')){
                Cart.ItemNumUpdate(target,target.value);
            }
         },*/
        'click':function(e){
            var target=$(e.target);
            if(target.hasClass('numadjust')){
                var num=target.hasClass('increase')?1:-1;
                var ipt=target.getParent('.numadjust-arr').getPrevious('input');
                if(num==-1&&ipt.value<0)return;
                Cart.ItemNumUpdate(ipt,num,e);
            }
            if(target.hasClass('delItem')){
                Cart.removeItem(target);
            }
        }
    });

}();
</script>
<script>
    /*
    收藏夹滚动播放

       new Switchable(document.getElement('.picscroll_cart'), {
            effect: 'scrollx',
            autoplay:false,
            steps: 4,
            prev:'.toleft',
            next:'.toright',
            hasTriggers:false,
            viewSize: [880,216],
            content:'.pics-content_cart',
            panels:'dl[img_id]',
            circular: false,
            haslrbtn:true,
            disableCls: 'disable',
            lazyDataType: 'img',
            onInit:function(){
                if(Browser.ie6){
                       var wid = document.getElement('.pics-content_cart').getStyle('width');
                       document.getElement('.pics-content_cart').setStyle('width',parseInt(wid)+100);
                }
            }
        });





          $$('.GoodsSearchWrap .buy-select').each(function(el){
              el.removeEvent('mouseover').addEvent('mouseover',function(e):w
                var pos = $(e.target).getCoordinates();
            new Element('div',{'html':$(e.target.getNext('.buy-select-list').innerHTML})).inject(document.body);
    })});
  */
</script>

<!--<{script src='goodscupcake.js' app='b2c'}>-->
